Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

144
Views
Function is no longer found if I add "require" source

I have a function "loadDays()" that should be executed when the body-section is loaded:

<body onload="loadDays()">

In <script> I have my function loadDays():

<script>
    function loadDays() {
        // code
    }

Now I added src="https://requirejs.org/docs/release/2.3.5/minified/require.js" to the <script>-tag, to make use of require inside my function.

While it does recognize require then, it throws a new error:

"Uncaught ReferenceError: loadDays is not defined

at onload

What am I missing?

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

If <script> tag has src attribute, then any content inside this tag is ignored.

You should add 2 separate tags:

<script src="https://requirejs.org/docs/release/2.3.5/minified/require.js"></script>
<script>
    function loadDays() {
        // code
    }
</script>

about 4 years ago · Juan Pablo Isaza Report

0

I've checked requireJS, so you should actually do it like this, as they said in the docs:

<!DOCTYPE html>
<html>
    <head>
        <title>My Sample Project</title>
        <!-- data-main attribute tells require.js to load
             scripts/main.js after require.js loads. -->
        <script data-main="scripts/main" src="https://requirejs.org/docs/release/2.3.5/minified/require.js"></script>
    </head>
    <body>
        <h1>My Sample Project</h1>
    </body>
</html>

Then add a main.js file in the scripts folder, and put your function inside of it.

    function loadDays() {
        // code
    }
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!